package net.easyjava.admin.constants;

import net.easyjava.tools.BaseEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wenxiaoning on 15/12/26.
 */
public enum  MenuConstants implements BaseEnum{
    ARTICLE_MANAGE(1,0,"文章管理","",1),
    USER_MANAGE(2,0,"用户管理","",10),

    ARTICLE_LIST(3,1,"文章列表","/admin/article/list.html",1),
    USER_LIST(4,2,"用户列表","/admin/user/list.html",1),


    SYSTEM_MANAGE(5,0,"系统管理","",11),
    REFRESH_REDIS(6,5,"缓存列表","/admin/system/list.html",1),

    ;
    private MenuConstants(int id, int fatherId, String name, String url,int displayOrder) {
        this.id = id;
        this.fatherId = fatherId;
        this.name = name;
        this.url = url;
        this.displayOrder = displayOrder;
    }

    private int id;
    private int fatherId;
    private String name;
    private String url;
    private int displayOrder;
    private List<MenuConstants> subMenus;

    public int getId() {
        return id;
    }

    public int getFatherId() {
        return fatherId;
    }

    public String getName() {
        return name;
    }

    public String getUrl() {
        return url;
    }

    public List<MenuConstants> getSubMenus() {
        return subMenus;
    }

    public void setSubMenus(List<MenuConstants> subMenus) {
        this.subMenus = subMenus;
    }

    public int getDisplayOrder() {
        return displayOrder;
    }

    /**
     * 获取级联菜单
     * @param fatherId
     * @return
     */
    public static List<MenuConstants> getList(int fatherId){
        MenuConstants[] menuConstantses =  MenuConstants.values();
        List<MenuConstants> menuConstantsList = new ArrayList<MenuConstants>();
        for (MenuConstants menuConstants:menuConstantses){
            if(menuConstants.getFatherId() ==fatherId){
                if(fatherId ==0){
                    //获取子菜单
                    menuConstants.setSubMenus(getList(menuConstants.getId()));
                }
                //添加
                menuConstantsList.add(menuConstants);
            }
        }
        return menuConstantsList;
    }






    public static void main(String[] args) {
        List<MenuConstants> menuConstantses =  MenuConstants.getList(0);

        for (int i = 0; i <menuConstantses.size(); i++) {
            System.out.println("menuConstantses = " + menuConstantses.get(i).getName());
            List<MenuConstants> sub =  menuConstantses.get(i).getSubMenus();
            for (MenuConstants menuConstants:sub){
                System.out.println("=========menuConstants.getName() = " +menuConstants.getName());
            }
        }
    }
}
